<%@ page import="java.io.InputStream" %>
<%@ page import="java.io.BufferedReader" %>
<%@ page import="java.io.InputStreamReader" %>
<%@ page import="java.nio.charset.StandardCharsets" %>
<%@ page import="cn.hutool.json.JSONUtil" %>
<%@ page import="java.io.IOException" %>
<%@ page import="org.slf4j.Logger" %>
<%@ page import="org.slf4j.LoggerFactory" %>
<%@ page import="weaver.general.Util" %>
<%@ page import="weaver.conn.RecordSet" %>
<%@ page import="java.util.stream.Collectors" %>
<%@ page import="com.alibaba.fastjson.JSONObject" %>
<%@ page import="com.alibaba.fastjson.JSONArray" %>
<%@ page import="java.util.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%!
    private Logger logger= LoggerFactory.getLogger(this.getClass());
    public void excuteSupporetRole(StringBuilder cjRHrmresouce, Integer inncodeID,StringBuilder znbscjgwStr,String filedName,String tableName){
//        String sqluf_hotelpositions="select wxid from uf_Master_Hotel_Role where inncode="+inncodeID+" and "+Util.getSubINClause(znbscjgwStr.toString(),"hotelrole","in");//中心岗位的数据,酒店岗位的数据
        List<String> zsZsList= Arrays.stream(znbscjgwStr.toString().split(",")).filter(s->!",".equals(s)).collect(Collectors.toList());
        zsZsList.forEach(r->{
            String sqluf_hotelpositions="select wxid from "+tableName+" where inncode="+inncodeID+" and find_in_set('" +r+"',"+filedName+")  and zt=0 order by id desc limit 0,1";//中心岗位的数据,酒店岗位的数据
            logger.info("sqluf_hotelpositionsUF1111=====>"+sqluf_hotelpositions+"===filedName===>"+filedName);
            RecordSet recordSetCj=new RecordSet();
            recordSetCj.execute(sqluf_hotelpositions);
//        StringBuilder cjRHrmresouce=new StringBuilder();
            while (recordSetCj.next()){
                RecordSet recordSetPeoPle=new RecordSet();
                recordSetPeoPle.execute("select id from hrmresource where loginid='"+recordSetCj.getString("wxid")+"' and loginid <>''");
                if (recordSetPeoPle.next()){
                    cjRHrmresouce.append(recordSetPeoPle.getInt("id")).append(",");
                }
            }
        });


    }
    public  String getPostData(InputStream in, int size, String charset) {
        if (in != null && size > 0) {
            byte[] buf = new byte[size];
            try {
                in.read(buf);
                if (charset == null || charset.length() == 0)
                    return new String(buf);
                else {
                    return new String(buf, charset);
                }
            } catch (IOException e) {
                e.printStackTrace();
            }finally {
                try {
                    in.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }
%>

<%
    response.setContentType("text/html;charset=utf-8");
        logger.info("intoUfJsp===>");
    String jsonStr=getPostData(request.getInputStream(),request.getContentLength(),"");
    logger.info("jsonStr===>"+jsonStr);
    JSONObject jsonObjectParamTwo = (JSONObject) JSONObject.parse(jsonStr);
    logger.info("jsonObjectParamTwo=====>{}",jsonObjectParamTwo);
    JSONArray jdgwArray=jsonObjectParamTwo.getJSONArray("jdgw");//酒店岗位数据相关
    JSONArray znbmArray=jsonObjectParamTwo.getJSONArray("znbm");//中心岗位数据相关
    Integer inncode=jsonObjectParamTwo.getInteger("jddm");
    StringBuilder crmPeopleReource=new StringBuilder();
    StringBuilder gwIdValue=new StringBuilder();
    StringBuilder znIdValue=new StringBuilder();

    for (int i=0;i<jdgwArray.size();i++){
        JSONObject jsonObjectParam=jdgwArray.getJSONObject(i);
        String id=jsonObjectParam.getString("id");
        gwIdValue.append(id);
        if(i!=jdgwArray.size()-1){
            gwIdValue .append(",");
        }

    }
    excuteSupporetRole(crmPeopleReource,inncode,gwIdValue,"hotelrole","uf_Master_Hotel_Role");
    logger.info("crmPeopleReource===>{}",crmPeopleReource);
    for (int i=0;i<znbmArray.size();i++){
        JSONObject jsonObjectParam=znbmArray.getJSONObject(i);
        String id=jsonObjectParam.getString("id");
        znIdValue.append(id);
        if(i!=znbmArray.size()-1){
            znIdValue .append(",");
        }
    }
    logger.info("gwIdValue====>"+gwIdValue+"====>znIdValue=====>"+znIdValue+"<br/>");
    excuteSupporetRole(crmPeopleReource,inncode,znIdValue,"SupportRole","uf_zczx");
    logger.info("crmPeopleReourceTwo===>{}",crmPeopleReource);
    List<String> resultList=Arrays.asList(crmPeopleReource.toString().split(",")).stream().filter(r->!r.equals(",")).distinct().collect(Collectors.toList());
    logger.info("resultList===>"+resultList);
    List<Map<String,String>> resultMapList=new ArrayList<>();
    for (String s : resultList) {
        Map<String,String> itemMap=new HashMap<>();
        RecordSet recordSet=new RecordSet();
        recordSet.executeQuery("select lastname from hrmresource where id=?",s);
        if(recordSet.next()){
            itemMap.put("id",s);
            itemMap.put("name",recordSet.getString("lastname"));
        }else {
            itemMap.put("id",s);
            itemMap.put("name","");
        }
        resultMapList.add(itemMap);
    }
    response.getWriter().write(JSONUtil.toJsonStr(resultMapList));
%>